<?php 
/**
 * 见解
 DROP TABLE IF EXISTS `dict_thesis`;
CREATE TABLE `dict_thesis` (
  `t_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `u_id` int(11) NOT NULL,
  `d_id` int(11) NOT NULL,
  `thesis` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`t_id`,`u_id`,`d_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 */
Class ThesisModel extends Model{
  protected $_link = array(
      'Comment' => array(
          'mapping_type'  => HAS_MANY,
          'class_name'    => 'Comment',
          'foreign_key'   => 't_id',
          'mapping_name'  => 'comments',
          // 'mapping_order' => ''
        ),
    );
  public function selectAllThesis()
  {
    return $this->select();
  }

  public function selectThesisByTid(int $t_id)
  {
    return $this->where('t_id=' . $t_id)->find();
  }

  public function selectThesisByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id)->select();
  }

  public function selectThesisByDid(int $d_id)
  {
    return $this->where('d_id=' . $d_id)->select();
  }

  public function addThesis($data)
  {
    return $this->add($data);
  }

  public function updateThesis($data)
  {
    return $this->save($data);
  }

  public function delThesisByTid(int $t_id)
  {
    return $this->where('t_id=' . $t_id)->relation("Comment")->delete();
  }

  public function delThesisByUid(int $u_id)
  {
    return $this->where('u_id=' . $u_id)->relation("Comment")->delete();
  }

  public function delTheisByDid(int $d_id)
  {
    return $this->where('d_id=' . $d_id)->relation("Comment")->delete();
  }
}
 ?>